package com.hurui.xiaoming.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.hurui.xiaoming.R;
import com.hurui.xiaoming.bean.Li_MyList_Result;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by hurui on 2017/7/21.
 */

public class CreditorAdapter extends RecyclerView.Adapter<CreditorAdapter.FinanceHolder> {

    private Context context ;
    private List<Li_MyList_Result.DataBean> lists ;
    public CreditorAdapter(Context context ){
        this.context = context ;
       lists=new ArrayList<>();
    }

    public void notifyData(List<Li_MyList_Result.DataBean> list) {
            lists.addAll(list);
        notifyDataSetChanged();
    }
    @Override
    public FinanceHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.creditor_item , parent , false);
        return new FinanceHolder(view);
    }

    @Override
    public void onBindViewHolder(FinanceHolder holder, int position) {
        Li_MyList_Result.DataBean dataBean = lists.get(position);


        switch (dataBean.getOi_state()) {
            case "1":
                //借款中
                holder.oi_num.setText("订单编号:"+dataBean.getOi_num());
                holder.order_info_tv.setText("借款" + dataBean.getOi_jkprice() + "元，分" + dataBean.getOi_jkloans() + "期  3-" + dataBean.getNowloans());
                holder.order_status_tv.setText("待还款");
//                holder.order_money_tv.setText(dataBean.getMyyhprice());
                if (dataBean.getHktime() != null)
                    holder.order_time_tv.setText("还款日期: " + dataBean.getHktime());
                holder.send_btn.setText("立即打款");
                break;
            case "3":
                holder.order_info_tv.setText("借款" + dataBean.getOi_jkprice() + "元，分" + dataBean.getOi_jkloans() + "期");
                holder.order_status_tv.setText("已还款");
                holder.order_moeny.setText(dataBean.getMyyhprice());
                if (dataBean.getHktime() != null)
                    holder.order_time_tv.setText("还款日期: " + dataBean.getHktime());
                holder.send_btn.setVisibility(View.GONE);
                break;
            case "4":
                holder.order_info_tv.setText("借款" + dataBean.getOi_jkprice() + "元，分" + dataBean.getOi_jkloans() + "期  3-" + dataBean.getNowloans());
                holder.order_status_tv.setText("已逾期");
                holder.order_moeny.setText("您已逾期");
                if (dataBean.getHktime() != null)
                    holder.order_time_tv.setText("还款日期: " + dataBean.getHktime());
                holder.send_btn.setText("立即打款");
                break;
            case "5":
                holder.order_info_tv.setText("借款" + dataBean.getOi_jkprice() + "元，分" + dataBean.getOi_jkloans() + "期");
                holder.order_status_tv.setText("已还款");
                holder.order_moeny.setText(dataBean.getMyyhprice());
                if (dataBean.getHktime() != null)
                    holder.order_time_tv.setText("还款日期: " + dataBean.getHktime());
                holder.send_btn.setVisibility(View.GONE);

                break;
        }
    }
    @Override
    public int getItemCount() {
        return lists.size();
    }

    public class FinanceHolder extends RecyclerView.ViewHolder{

        private final TextView oi_num,order_status_tv,order_info_tv,zhifubao_tv,order_moeny,
                order_time_tv,copy_btn,send_btn;

        public FinanceHolder(View itemView) {
            super(itemView);
            oi_num = ((TextView) itemView.findViewById(R.id.dingdan_code));
            order_status_tv = ((TextView) itemView.findViewById(R.id.order_status_tv));
            order_info_tv = ((TextView) itemView.findViewById(R.id.order_info_tv));
            order_moeny = ((TextView) itemView.findViewById(R.id.order_moeny));
            zhifubao_tv = ((TextView) itemView.findViewById(R.id.zhifubao_tv));
            order_time_tv = ((TextView) itemView.findViewById(R.id.order_time_tv));
            copy_btn = ((TextView) itemView.findViewById(R.id.copy_btn));
            send_btn = ((TextView) itemView.findViewById(R.id.send_btn));


        }
    }
}
